<!DOCTYPE html>
<html>
{include file="public/head"}

<body>
    {include file="public/nav"} {include file="problem/nav-2"}
    <div class="layui-container">
        <div class="layui-row layui-col-space15">

            {if condition="$coderank"}

            {else /}
            <div class="fly-panel">
                <form method="get" action="{:url('web/Problem/status')}">
                    <div class="layui-form" style="text-align: center;">
                        <div class="layui-inline status-input-comb">

                            <input type="text" name="pid" placeholder="请输入题目ID" class="layui-input" value="{$urldata.problem_id?$urldata.problem_id:''}">
                        </div>
                        <div class="layui-inline status-input-comb">
                            <input type="text" name="userid" placeholder="请输入用户名" class="layui-input" value="{$urldata.user_id?$urldata.user_id:''}">
                        </div>

                        <div class="layui-input-inline status-input-comb">
                            <select name="language">
                                <option value="-1">--语言--</option>
                                <?php 
                                foreach ($lang as $k=>$v){
                                if($lang_mask&(1<<$k)){
                                if(isset($urldata['language'])&&$urldata['language']==$k){
                                echo ' <option value="'.$k.'" selected="">'.$v.'</option>';
                                }
                                else {
                                echo ' <option value="'.$k.'" >'.$v.'</option>';
                                }
                                }
                                }

                                ?>
                            </select>
                        </div>
                        <div class="layui-input-inline status-input-comb">
                            <select name="result">
                                <option value="-1">--结果--</option>
                                <?php 
                                for($i=4;$i<=13;$i++)
                                {
                                if(isset($urldata['result'])&&$urldata['result']==$i){
                                echo ' <option value="'.$i.'" selected="">'.$resultset[$i].'</option>';
                                }
                                else {
                                echo ' <option value="'.$i.'" >'.$resultset[$i].'</option>';
                                }
                                }
                                for($i=0;$i<4;$i++)
                                {
                                if(isset($urldata['result'])&&$urldata['result']==$i){
                                echo ' <option value="'.$i.'" selected="">'.$resultset[$i].'</option>';
                                }
                                else {
                                echo ' <option value="'.$i.'" >'.$resultset[$i].'</option>';
                                }
                                }

                                ?>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn" type="submit">开始查找</button>
                        </div>
                        <div class="layui-inline">
                            <a href="{:url('web/Problem/status')}?userid={$login_userid}" class="layui-btn" type="submit">我的提交</a>
                        </div>
                    </div>
                </form>
            </div>     {/if}


            <div style="text-align: center;">
                {$list->render()}
            </div>
            <div class="fly-panel status-list" style="margin-bottom: 0;">
                <ul class="fly-list">
                    <table class="layui-table" id="statuslist">
                        <thead>
                            <tr class="layui-bg-green">
                                {if condition="$coderank"}
                                 <th>rank</th>
                                {/if}
                                <th>运行编号</th>
                                <th>用户ID</th>
                                <th>题目ID</th>
                                <th>结果</th>
                                <th>语言</th>
                                <th>耗时</th>
                                <th>内存</th>
                                <th>代码长度</th>
                                <th>提交时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach name="list" item="v"}
                            <tr>
                                {if condition="$coderank"}
                                <td>{++$rankstart}</td>
                                {/if}
                                {if condition="(isset($is_link[$key])&&$is_link[$key]==true)"}
                                <td><a class="fly-link fly-joinad query_code" href="javascript:;" id="{$v.solution_id}" pid="{$v.problem_id}">{$v.solution_id}</a></td>
                                {else /} 
                                <td>{$v.solution_id}</td>
                                {/if}
                                <td><a class="fly-link fly-joinad" href="{:url('web/Account/info','user_id='.$v['user_id'])}">{$v.user_id}</a></td>
                                <td><a class="fly-link fly-joinad" href="{:url('web/Problem/problem','pid='.$v['problem_id'])}">{$v.problem_id}</a></td>
                                <td>
                                       <span id='res-{$v.solution_id}' pid="{$v.solution_id}" class="{if condition="$v.result<4"}nyoj-wait{/if}" style="color: {eq name='$v.result' value='4'}#5FB878;{else/}#FF5722{/eq}">
                                          {$resultset[$v.result]}
                                        {if condition="$v.result<4"}
                                            <i  class="layui-icon layui-anim-rotate layui-anim-loop" style="color: black;float: right;">&#xe63d;</i>
                                        {/if}                                      
                                       </span>
                                       
                                
                                </td>

                                <td>{$lang[$v.language]}</td>


                                <td id='time-{$v.solution_id}'>{$v.time}ms</td>
                                <td id="mem-{$v.solution_id}">{$v.memory} KB</td>
                                <td>{$v.code_length} B</td>
                                <td>{$v.in_date}</td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </ul>
            </div>
            <div style="text-align: center;">
                {$list->render()}
            </div>
        </div>
    </div>
    {include file="public/foot"}
</body>
<script>
    layui.use(['jquery','layer'],function(){
        var $ = layui.jquery;
        var layer = layui.layer;

        $('.query_code').click(function(){
            var sid = $(this).attr('id');
            var pid = $(this).attr('pid');
            var jq = $(this);
            // console.log('sid='+sid);
            // console.log('pid='+pid);
            $.ajax({
                url:"{:url('web/problem/query_code')}",
                type:'post',
                data:{"sid":sid,"pid":pid},
                dataType:'JSON',
                success:function(res){
                    // console.log('max_time='+res.max_time);
                    // console.log('now_time='+res.now);
                    // console.log('sid1='+sid);
                    // console.log('pid1='+pid);
                    if(res.result==1) {
                        layer.confirm(res.msg, {
                        // skin: 'layui-layer-lan',
                        title:'提示',
                        btn: ['确定','取消'] //按钮
                        }, function(){
                            $.ajax({
                                // console.log('sid2='+sid);
                                // console.log('pid2='+pid);
                                url:"{:url('web/problem/cost_code')}",
                                type:'post',
                                data:{"sid":sid,"pid":pid},
                                dataType:'JSON',
                                shadeClose: true, 
                                success:function(res){
                                    window.location.href="/showcode/"+sid;
                                },
                                error:function(res) {

                                }
                            });
                        }, function(){
                        // layer.msg('也可以这样', {
                        //     time: 20000, //20s后自动关闭
                        //     btn: ['明白了', '知道了']
                        //     });
                        });
                    } else if(res.result==0){
                        layer.confirm(res.msg, {
                        // skin: 'layui-layer-lan',
                        shadeClose: true, 
                        title:'提示',
                        btn: ['确定'] //按钮
                        }, function(){
                        window.location.href="/showcode/"+sid;
                        });
                        // window.location.href="/showcode/"+sid;   
                    } else if(res.result==-1){
                        window.location.href="/showcode/"+sid;
                    }
                },
                error:function() {
                    layer.msg('进入后台失败');
                }
            });
        });
    });




    var clocktime;
    function do_something(){
        layui.use(['jquery'],function(){
            var $=layui.jquery;
            var mydata='';
            $('.nyoj-wait').each(function(){
                mydata+=($(this).attr('pid')+'_');
            });
            if(mydata==='')
            {
                clearInterval(clocktime);
                return ;
            }
            $.ajax({
                url:'/api/submit-status-'+mydata,
                success:function(res){
                   //console.log(res);
                    for(var x in res){
                        var i=res[x];
                        //console.log(i);
                        if(i.code===0){
                            if(i.result>4){
                                $('#res-'+i.solution_id).html(i.result_zh);
                                $('#res-'+i.solution_id).removeClass('nyoj-wait');
                                $("#time-"+i.solution_id).text(i.time+' ms');
                                $("#mem-"+i.solution_id).html(i.memory+' KB');
                            }
                            else if(i.result===4){
                                $('#res-'+i.solution_id).html(i.result_zh);
                                $('#res-'+i.solution_id).css("color","#5FB878");
                                $('#res-'+i.solution_id).removeClass('nyoj-wait');
                                
                                $("#time-"+i.solution_id).html(i.time+' ms');
                                $("#mem-"+i.solution_id).html(i.memory+' KB');
                            }
                            else 
                            {
                                $('#res-'+i.solution_id).html(i.result_zh+'<i  class="layui-icon layui-anim-rotate layui-anim-loop" style="color: black;float: right;">&#xe63d;</i>');
                            }
                        }
                    }
                }
            });
        });
    }
    clocktime=setInterval('do_something()',3000);
    setTimeout('clearInterval(clocktime);', 30000);
</script>
</html>
 